package com.codeyang.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * 描述: TO-删除标志-DO
 *
 * @author CodeYang_Site
 * @version 2021/5/25 10:36
 */
@RestController
public class ConfigRefreshController {

    @Autowired
    private RestTemplate restTemplate;


    /**
     * 端口不能写死 拿yml中的配置
     */
    @Value("${server.port}")
    private Integer port;

    @PostMapping("busAllRefresh")
    public ResponseEntity<String> info() {
        String URL = "http://localhost:" + port + "/actuator/bus-refresh";

        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("content-type", "application/json;charset=utf-8");
        HttpEntity<String> httpEntity = new HttpEntity<>(httpHeaders);
        ResponseEntity<String> responseEntity = restTemplate.postForEntity(URL, httpEntity, String.class);
        //这个请求是没有任何返回值就是成功
        if (responseEntity.getStatusCode().equals(HttpStatus.NO_CONTENT)) {
            return ResponseEntity.ok("刷新成功");
        }
        return ResponseEntity.badRequest().body("刷新失败");
    }
}
